16
Sets the value of i to be 1. Therefore we can describe this line with help of the ADT notation as follows:
Perform operation set with argument 1 on the Integer instance i. This is written as follows: i.set(1).
The second level is the implementation level, where an actual representation is chosen for the operation. In C the equal sign ``='' implements the set() operation.
Implementation of ADT:
Step 2: set(1)
MODULAR PROGRAMMING
int i, j, k; /* Define three integers */
i = 1; /* Assign 1 to integer i */
j = 2; /* Assign 2 to integer j */
k = i + j; /* Assign the sum of i and j to k */
Consider the ADT Integer. Outline the relationship to the ADT Integer in the following code:
We now have a representation at two levels. The first level is the ADT level where we express everything that is done to an instance of this ADT by the invocation of defined operations. At this level, pre- and postconditions are used to describe what actually happens. In the following example, these conditions are enclosed in curly brackets.
{ Precondition: i = n where n is any Integer }
i.set(1)
{ Postcondition: i = 1 }